package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.msg.rest.service.IWxMpMsgTemplateService;
import com.ibeeking.found.msg.service.common.query.WxMpMsgTemplateQuery;
import com.ibeeking.found.msg.service.common.vo.WxMpMsgTemplateVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.alibaba.nacos.common.http.param.MediaType;

import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MpTemplateMsgController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-30 14:12
 **/
@RestController
@RequestMapping("/msg/wxMpMsgTemplate/v1")
public class WxMpMsgTemplateController {

    @Resource
    private IWxMpMsgTemplateService wxMpMsgTemplateServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询微信公众号模板消息列表")
    @PostMapping(value = "/queryTemplateList", produces = MediaType.APPLICATION_JSON)
    public List<WxMpMsgTemplateVO> queryTemplateList(@RequestBody WxMpMsgTemplateQuery query) {
        return wxMpMsgTemplateServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除微信公众号消息模板")
    @GetMapping(value = "/delTemplate/{id}")
    public Boolean delTemplate(@PathVariable("id") Long id) {
        return wxMpMsgTemplateServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "同步微信公众号消息模板")
    @PostMapping(value = "/syncWxMpMsgTemplateListFromWx")
    public Integer syncWxMaMsgTemplateListFromWx() {
        return wxMpMsgTemplateServiceImpl.syncWxMpMsgTemplateFromWx();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "从微信查询微信公众号消息模板")
    @PostMapping(value = "/queryMsgTemplateListFromWx")
    public List<WxMpTemplate> queryMsgTemplateListFromWx() {
        return wxMpMsgTemplateServiceImpl.queryMsgTemplateListFromWx();
    }

}
